#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>

void sys_err(const char *str){
	perror(str);
	exit(1);
}

void *tfn(void *arg){
	int i = (int)arg;
	if (i == 2){
		pthread_exit(NULL);
	}
	printf("thread %dth:pid = %d, tid = %lu\n",i,getpid(),pthread_self());
	return NULL;
}


int main(int argc, char *argv[]){
	printf("main:pid = %d, tid = %lu\n",getpid(),pthread_self());
	pthread_t tid;

	int i = 0;
	for(;i < 5 ; i++){
		int ret = pthread_create(&tid,NULL,tfn,(void *)i);
		if (ret != 0){
			sys_err("pthread_create error");
		}
	}
	pthread_exit((void*)0);
	
}


